package com.yricky.memoria.activity

import android.app.Activity
import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.activity.result.contract.ActivityResultContracts
import androidx.lifecycle.ViewModelProvider
import com.yricky.memoria.data.pojo.SectionQuery
import com.yricky.memoria.ui.component.SectionActivityContent
import com.yricky.memoria.ui.component.SectionViewModel
import com.yricky.memoria.utils.gson

/**
 * @author Yricky
 * @date 2021/11/28
 */
class SectionActivity:BaseActivity() {
    private val viewModel:SectionViewModel by lazy{
        ViewModelProvider(this)[SectionViewModel::class.java]
    }
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val sectionQuery:SectionQuery? = try {
            gson.fromJson(intent.getStringExtra("query"),SectionQuery::class.java)
        }catch (e:Throwable){
            finish()
            null
        }
        if(sectionQuery == null){
            finish()
        }else if(!viewModel.setRequest(sectionQuery)){
            finish()
        }
        setContent {
            SectionActivityContent(viewModel = viewModel)
        }
    }
}